package com.zmq.ha.client.core;

import java.io.IOException;
import java.lang.reflect.Proxy;
import java.util.concurrent.TimeoutException;

import com.rabbitmq.client.Connection;
import com.zmq.ha.client.resource.ConnectionOption;
import com.zmq.ha.client.runnable.RmqKeepAliveRunnable;


public class ConnectionBuilder {
	
private static final Class<?>[] CLASSE_TYPES = new Class<?>[]{Connection.class};

	static{
		new RmqKeepAliveRunnable();
	}
	public static final Connection createConnection(ConnectionOption option) throws IOException, TimeoutException{
		
		ConnectionWrapper connectionWrapper = new ConnectionWrapper(option);
		connectionWrapper.createConnection(false);
		Connection connectionProxy = (Connection) Proxy.newProxyInstance(Connection.class.getClassLoader(), CLASSE_TYPES, connectionWrapper);
		return connectionProxy;
	}

}
